//
//  MoviePlayerView.m
//  OpenYourEyes
//
//  Created by 沈振烨 on 15/8/11.
//  Copyright (c) 2015年 沈振烨. All rights reserved.
//

#import "MoviePlayerView.h"

@implementation MoviePlayerView

// 初始化方法
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        CGFloat height = [UIScreen mainScreen].bounds.size.width;
        CGFloat width = [UIScreen mainScreen].bounds.size.height;
        
        // width = 667  height = 375
        NSLog(@"width = %f  height = %f",width,height);
        
        //  顶部的操作视图
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 55)];
        _topView.backgroundColor = [UIColor blackColor];
        _topView.alpha = 0.6;
        [self addSubview:_topView];
        //  顶部视图上添加返回按钮
        _returnButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_returnButton setImage:[UIImage imageNamed:@"iconfont-fanhui"] forState:UIControlStateNormal];
        _returnButton.frame = CGRectMake(10, 20, 25, 25);
        [_topView addSubview:_returnButton];
        
        //  顶部标题
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_returnButton.frame) + 5, 15, width / 2, 30)];
        _titleLabel.font = [UIFont systemFontOfSize:18];
        _titleLabel.textColor = [UIColor whiteColor];
        [_topView addSubview:_titleLabel];
        

        
        
        //  顶部视图添加下载按钮
        _downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _downloadButton.frame = CGRectMake(width - 150, 20, 28, 28);
        [_downloadButton setImage:[UIImage imageNamed:@"iconfont-download"] forState:UIControlStateNormal];
        [_topView addSubview:_downloadButton];
        
        //  顶部视图添加收藏按钮
        _collectionButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _collectionButton.frame = CGRectMake( width - 100, 20, 30, 30);
        [_collectionButton setImage:[UIImage imageNamed:@"iconfont-weishoucang"] forState:UIControlStateNormal];
        [_topView addSubview:_collectionButton];
        
        
        // 底部的操作视图
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, height - 50, width, 50)];
        _bottomView.backgroundColor = [UIColor blackColor];
        _bottomView.alpha = 0.6;
        [self addSubview:_bottomView];
        
        
        //  底部添加 当前时间 slider  总时间
        _currentTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 50, 20)];
        _currentTimeLabel.text = @"00:00";
        _currentTimeLabel.textColor = [UIColor whiteColor];
        [_bottomView addSubview:_currentTimeLabel];
        
        _totalTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(width - 60, 15, 50, 20)];
        _totalTimeLabel.textColor = [UIColor whiteColor];
        [_bottomView addSubview:_totalTimeLabel];
        
        //  添加一个缓存条,把slider覆盖在缓存条上面
        _progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
        _progressView.frame = CGRectMake(67.2, 23.8, width - 130 - 4, 0.8);
        // 设置缓存条的背景色
        _progressView.backgroundColor = [UIColor grayColor];
        [_bottomView addSubview:_progressView];
        
        
        //  添加一个自定义缓存条
        
        
        //  添加播放进度条
        _movieSlider = [[UISlider alloc] initWithFrame:CGRectMake(65, 10, width - 130, 30)];
        //  设置已播放进度条的颜色
        _movieSlider.minimumTrackTintColor = [UIColor colorWithRed:1 green:0.30 blue:0 alpha:1];
        //  没有播放的进度条设置透明色
        _movieSlider.maximumTrackTintColor = [UIColor clearColor];
        
        //  修改thumb 的颜色
        _movieSlider.continuous = YES;
        //  修改thumb 的样式
        [_movieSlider setThumbImage:[UIImage imageNamed:@"iconfont-shuxian"] forState:UIControlStateNormal];
        

        
        [_bottomView addSubview:_movieSlider];
        
        // 添加中间视图
        _centerView = [[UIView alloc] initWithFrame:CGRectMake(0, 55, width, height - 55 - 50)];
        _centerView.backgroundColor = [UIColor blackColor];
        _centerView.alpha = 0.60;
        [self addSubview:_centerView];
        
        
        
        //  添加播放按钮
        _playButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _playButton.frame = CGRectMake(width / 2 - 25, (height - 105) / 2 - 25, 50, 50);
        [_playButton setImage:[UIImage imageNamed:@"zanting"] forState:UIControlStateNormal];
        [_centerView addSubview:_playButton];
        
        //  添加增大音量的按钮
        _addVoiceButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _addVoiceButton.frame = CGRectMake(30, (height / 3) - (height / 6) - 30, 20, 20);
        [_addVoiceButton setImage:[UIImage imageNamed:@"iconfont-yinliangda"] forState:UIControlStateNormal];
        [_centerView addSubview:_addVoiceButton];
        
        //  添加减小音量的按钮
        _reduceVoiceButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _reduceVoiceButton.frame = CGRectMake(30, CGRectGetMaxY(_addVoiceButton.frame) + height / 3 + 30, 20, 20);
        [_reduceVoiceButton setImage:[UIImage imageNamed:@"iconfont-yinliangxiao"] forState:UIControlStateNormal];
        
        [_centerView addSubview:_reduceVoiceButton];
        
        // 添加声音的slider
        _voiceSlider = [[UISlider alloc] initWithFrame:CGRectMake( - (height / 3 / 2 - 30), height / 3 - 10, height / 3 + 20, 30)];
        _voiceSlider.transform = CGAffineTransformRotate(_voiceSlider.transform, -M_PI_2);
        //  0.0 默认为静音
        _voiceSlider.minimumValue = 0.0;
        //  1.0 默认为最大音量
        _voiceSlider.maximumValue = 1.0;
        //  点击播放默认音量为0.5
        _voiceSlider.value = 0.5;
        //  修改thumb 的颜色
        _voiceSlider.continuous = YES;
        //  修改颜色
        _voiceSlider.minimumTrackTintColor = [UIColor colorWithRed:1 green:0.30 blue:0 alpha:1];
        //  修改thumb 的样式
        [_voiceSlider setThumbImage:[UIImage imageNamed:@"iconfont-shuxian"] forState:UIControlStateNormal];
        [_centerView addSubview:_voiceSlider];
        
//        _collectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMidX(_collectionButton.frame) - 100, 10, 200, 30)];
//        NSLog(@"+++++---%f",CGRectGetMidX(_collectionButton.frame) - 85);
//        _collectionLabel.text = @"您已加入收藏";
//        _collectionLabel.backgroundColor = [UIColor blackColor];
//        _collectionLabel.textColor = [UIColor whiteColor];
//        _collectionLabel.font = [UIFont systemFontOfSize:20];
//        _collectionLabel.textAlignment = NSTextAlignmentCenter;
//        _collectionLabel.layer.cornerRadius = 10;
//        [_centerView addSubview:_collectionLabel];
        
        
    }
    return self;
}










/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
